<template>
    <div>
        <div class="block">
            <el-pagination background layout="prev, pager, next,total" :total="showd.length" @current-change="changeindex"
                :currentPage="currentPage" :page-size="pageSize">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import bus from "../JS/bus";
export default {
    data() {
        return {
            showd: [],//获取的新数据
            pageSize: 6,//每页显示的条数
            currentPage: 1//默认第一页
        }
    },
    watch: {
        showd() {
            this.currentPage = 1
            // console.log(1111);
            bus.$emit('send2', this.RenderData(this.showd))

        },
        currentPage() {
            bus.$emit('send2', this.RenderData(this.showd))
        }
    },
    methods: {
        RenderData(value) {
            let CurrentData = [];

            CurrentData = value.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
            // console.log(CurrentData);
            return CurrentData
        },
        changeindex(index) {
            this.currentPage = index
        }
    },
    created() {
        bus.$emit('send2', this.RenderData(this.showd))
        bus.$on('changdata', (val) => {
            // console.log(val);
            this.showd = val
        })
    }
}
</script>

<style lang="scss" scoped></style>